home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / rb / __init__.py next >
Encoding:
Python Source  |  2009-04-07  |  3.5 KB  |  117 lines

  1. # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
  2. #
  3. # Copyright 2006, James Livingston <doclivingston@gmail.com>
  4. # Copyright 2006, Ed Catmur <ed@catmur.co.uk>
  5. # Copyright 2007, Jonathan Matthew
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. #
  12. # The Rhythmbox authors hereby grant permission for non-GPL compatible
  13. # GStreamer plugins to be used and distributed together with GStreamer
  14. # and Rhythmbox. This permission is above and beyond the permissions granted
  15. # by the GPL license by which Rhythmbox is covered. If you modify this code
  16. # you may extend this exception to your version of the code, but you are not
  17. # obligated to do so. If you do not wish to do so, delete this exception
  18. # statement from your version.
  19. # This program is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. # GNU General Public License for more details.
  23. #
  24. # You should have received a copy of the GNU General Public License
  25. # along with this program; if not, write to the Free Software
  26. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
  27.  
  28. import sys
  29. import os.path
  30. import os
  31.  
  32. import gtk
  33.  
  34. # rb classes
  35. from Loader import Loader
  36. from Loader import ChunkLoader
  37. from Loader import UpdateCheck
  38. from Coroutine import Coroutine
  39.  
  40. #def _excepthandler (exc_class, exc_inst, trace):
  41. #    import sys
  42. #    # print out stuff ignoring our debug redirect
  43. #    sys.__excepthook__ (exc_class, exc_inst, trace)
  44.  
  45.  
  46. def try_load_icon(theme, icon, size, flags):
  47.     try:
  48.         return theme.load_icon(icon, size, flags)
  49.     except:
  50.         return None
  51.  
  52. def append_plugin_source_path(theme, iconpath):
  53.     # check for a Makefile.am in the dir the file was loaded from
  54.     fr = sys._getframe(1)
  55.     co = fr.f_code
  56.     filename = co.co_filename
  57.  
  58.     # and if found, append the icon path
  59.     dir = filename[:filename.rfind(os.sep)]
  60.     if os.path.exists(dir + "/Makefile.am"):
  61.         plugindir = dir[:dir.rfind(os.sep)]
  62.         icondir = plugindir + iconpath
  63.         theme.append_search_path(icondir)
  64.  
  65. def show_uri(uri):
  66.     # use gtk_show_uri if available, otherwise use gnome-vfs
  67.     if hasattr(gtk, 'show_uri'):
  68.         gtk.show_uri(gtk.gdk.Screen(), uri, 0)
  69.     else:
  70.         import gnomevfs
  71.         gnomevfs.url_show(uri)
  72.  
  73.  
  74. class _rbdebugfile:
  75.     def __init__(self, fn):
  76.         self.fn = fn
  77.  
  78.     def write(self, str):
  79.         if str == '\n':
  80.             return
  81.         import rb
  82.         fr = sys._getframe(1)
  83.  
  84.         co = fr.f_code
  85.         filename = co.co_filename
  86.  
  87.         # strip off the cwd, for if running uninstalled
  88.         cwd = os.getcwd()
  89.         if cwd[-1] != os.sep:
  90.             cwd += os.sep
  91.         if filename[:len(cwd)] == cwd:
  92.             filename = filename[len(cwd):]
  93.  
  94.         # add the class name to the method, if 'self' exists
  95.         methodname = co.co_name
  96.         if fr.f_locals.has_key('self'):
  97.             methodname = '%s.%s' % (fr.f_locals['self'].__class__.__name__, methodname)
  98.  
  99.         rb._debug (methodname, filename, co.co_firstlineno + fr.f_lineno,  True, str)
  100.  
  101.     def close(self):         pass
  102.     def flush(self):         pass
  103.     def fileno(self):        return self.fn
  104.     def isatty(self):        return 0
  105.     def read(self, a):       return ''
  106.     def readline(self):      return ''
  107.     def readlines(self):     return []
  108.     writelines = write
  109.     def seek(self, a):       raise IOError, (29, 'Illegal seek')
  110.     def tell(self):          raise IOError, (29, 'Illegal seek')
  111.     truncate = tell
  112.  
  113. sys.stdout = _rbdebugfile(sys.stdout.fileno())
  114. #sys.excepthook = _excepthandler
  115.  
  116.